<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="google-site-verification" content="yF8HXsFuCTrePDFRnSkN2kkzV2ypBjtywzXsfVXOOV8">
  <meta name="baidu-site-verification" content="VxrVAiQAZ9">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yang0033.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":true},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="牛肉炒饭不要香菜，老板收钱">
<meta property="og:type" content="website">
<meta property="og:title" content="SuperYang&#96;s Blog">
<meta property="og:url" content="http://yang0033.gitee.io/index.html">
<meta property="og:site_name" content="SuperYang&#96;s Blog">
<meta property="og:description" content="牛肉炒饭不要香菜，老板收钱">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="SuperYang">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yang0033.gitee.io/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>

  <title>SuperYang`s Blog</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-71812998-3"></script>
    <script>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-71812998-3');
      }
    </script>


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8ff3295288514de6f89f314c23ee40ab";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">SuperYang`s Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">落魄程序员在线炒饭</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-message">

    <a href="/message/" rel="section"><i class="fa fa-music fa-fw"></i>留言板 | Music</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content index posts-expand">
            
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/09/09/OC-%E5%86%85%E5%AD%98%E5%AF%B9%E5%85%B6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/09/09/OC-%E5%86%85%E5%AD%98%E5%AF%B9%E5%85%B6/" class="post-title-link" itemprop="url">OC 内存对其原理分析</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-09-09 10:58:32 / 修改时间：21:52:07" itemprop="dateCreated datePublished" datetime="2020-09-09T10:58:32+08:00">2020-09-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/OC%E5%BA%95%E5%B1%82/" itemprop="url" rel="index"><span itemprop="name">OC底层</span></a>
                </span>
            </span>

          
            <span id="/2020/09/09/OC-%E5%86%85%E5%AD%98%E5%AF%B9%E5%85%B6/" class="post-meta-item leancloud_visitors" data-flag-title="OC 内存对其原理分析" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/09/09/OC-%E5%86%85%E5%AD%98%E5%AF%B9%E5%85%B6/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/09/09/OC-%E5%86%85%E5%AD%98%E5%AF%B9%E5%85%B6/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>上一篇文章我们讲到 alloc 在开辟内存空间之前，对对要分配的内存空间提前进行计算，并最终使用 16 字节对其方法进行对其，提升了读取的效率。但是16 字节对其之前，如何计算对象实际需要的空间呢？</p>
<h2 id="1-对象内存分析"><a href="#1-对象内存分析" class="headerlink" title="1. 对象内存分析"></a>1. 对象内存分析</h2><p>先展示一段测试代码</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">LGPerson</span> : <span class="title">NSObject</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span> *name;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span> *name1;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">assign</span>) <span class="keyword">short</span> a;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">assign</span>) <span class="keyword">int</span> b;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">assign</span>) <span class="keyword">double</span> c;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 调用  </span></span><br><span class="line">LGPerson *person = [[LGPerson alloc] init];</span><br><span class="line"></span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"sizeof——%lu"</span>, <span class="keyword">sizeof</span>([person <span class="keyword">class</span>]));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"class_getInstanceSize——%lu"</span>, class_getInstanceSize([person <span class="keyword">class</span>]));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"malloc_size——%lu"</span>, malloc_size((__bridge <span class="keyword">const</span> <span class="keyword">void</span> *)(person)));</span><br><span class="line"></span><br><span class="line"><span class="keyword">sizeof</span>——<span class="number">8</span></span><br><span class="line">class_getInstanceSize——<span class="number">40</span></span><br><span class="line">malloc_size——<span class="number">48</span></span><br></pre></td></tr></table></figure>

<p>这里可以发现，对于类本身，sizeof 可以查询到它所占用的地址空间只有 8 位。</p>
<p>而 class_getInstanceSize 为何是 40？没有 16 进制对其？</p>
<p>其实 class_getInstanceSize 获取到的是实例对象实际需要占用的内存空间，而且实际使用一般只会做 8 字节对齐。</p>
<p>而 malloc_size 则是系统实际为该实例对象分配的空间。也就是经过 16 字节对其后的效果。</p>
<h2 id="2-结构体内存对齐"><a href="#2-结构体内存对齐" class="headerlink" title="2. 结构体内存对齐"></a>2. 结构体内存对齐</h2><p>看完了对象，我们看下结构体是如何进行内存对齐的。（实际上要比对象对其要简单些，并且不涉及 16 进制对其的优化，能更直观的得出内存空间实际占用的计算）</p>
<p><strong>预备知识</strong></p>
<p>在展示实例之前，我们先看下实例中用到的类型的内存空间情况</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"double size %lu"</span>, <span class="keyword">sizeof</span>(<span class="keyword">double</span>));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"int size%lu"</span>, <span class="keyword">sizeof</span>(<span class="keyword">int</span>));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"short size %lu"</span>, <span class="keyword">sizeof</span>(<span class="keyword">short</span>));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"char size %lu"</span>, <span class="keyword">sizeof</span>(<span class="keyword">char</span>));</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"NSString size %lu"</span>, <span class="keyword">sizeof</span>(<span class="built_in">NSString</span> *));</span><br><span class="line"></span><br><span class="line"><span class="comment">// double size 8</span></span><br><span class="line"><span class="comment">// int size 4</span></span><br><span class="line"><span class="comment">// short size 2</span></span><br><span class="line"><span class="comment">// char size 1</span></span><br><span class="line"><span class="comment">// NSString * size 8（存储地址）</span></span><br></pre></td></tr></table></figure>

<p><strong>初级案例</strong></p>
<p>ok，这些类型的空间大小大家应该熟悉了。下面介绍实例</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> Str1 &#123;</span><br><span class="line">  <span class="keyword">int</span> o;</span><br><span class="line">  <span class="keyword">short</span> s;</span><br><span class="line">  <span class="keyword">char</span> a;</span><br><span class="line">  <span class="keyword">double</span> c;</span><br><span class="line">  <span class="built_in">NSString</span> *x;</span><br><span class="line">&#125; S1;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> Str2 &#123;</span><br><span class="line">  <span class="keyword">double</span> a;</span><br><span class="line">  <span class="keyword">int</span> d;</span><br><span class="line">  <span class="keyword">short</span> b;</span><br><span class="line">  <span class="keyword">char</span> c;</span><br><span class="line">  S1 s1;</span><br><span class="line">&#125; S2;</span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"%lu"</span>, <span class="keyword">sizeof</span>(S1)); <span class="comment">// 24</span></span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"%lu"</span>, <span class="keyword">sizeof</span>(S2)); <span class="comment">// 40</span></span><br></pre></td></tr></table></figure>

<p>我们先来看下结构体 Str1 的内存大小 - 16。</p>
<p>实际上，基础类型的存储位置为栈内存，而结构体的存储也使用了内存对其的技术，用于减少 cpu 的访问内存次数，提升读取效率。</p>
<p>首先我们需要了解一下结构体内存对其的规则：</p>
<ol>
<li>结构体变量的首地址是其最长基本类型成员的整数倍；</li>
<li>结构体每个成员相对于结构体首地址的偏移量（offset）都是成员大小的整数倍，如不满足，对前一个成员填充字节以满足；</li>
<li>结构体的总大小为结构体最大基本类型成员变量大小的整数倍；</li>
<li>结构体中的成员变量都是分配在连续的内存空间中。</li>
</ol>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> Str1 &#123;</span><br><span class="line">  <span class="keyword">int</span> o; <span class="comment">// 占用 4 字节，分别为 0 ~ 3</span></span><br><span class="line">  <span class="keyword">short</span> s; <span class="comment">// 占用 2 字节，分别为 4 ~ 5</span></span><br><span class="line">  <span class="keyword">char</span> a; <span class="comment">// 占用 1 字节， 分别为 6</span></span><br><span class="line">  <span class="built_in">NSString</span> *x; <span class="comment">// 占用8字节, 但由于规则2限制，需要对空间 7 进行填充，实际存储位置为 8 ~ 15</span></span><br><span class="line">  <span class="keyword">double</span> c; <span class="comment">// 占用8字节，分别为 16 - 23</span></span><br><span class="line">&#125; S1; <span class="comment">// 根据规则3，最大成员大小为8，0~23 总共占用24字节，刚好符合 8 的倍数。</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">NSLog</span>(<span class="string">@"%lu"</span>, S1); <span class="comment">// 24</span></span><br></pre></td></tr></table></figure>

<p>所以，根据规则，我们得出上述结构体 Str1 内存大小为 24 字节。</p>
<p><strong>进阶案例</strong></p>
<p>上面案例中，str2 是一个嵌套类型结构体，他的大小又是如何求得的呢？</p>
<h5 id="💡知识点：结构体嵌套的内存对其方式"><a href="#💡知识点：结构体嵌套的内存对其方式" class="headerlink" title="💡知识点：结构体嵌套的内存对其方式"></a>💡知识点：结构体嵌套的内存对其方式</h5><p>如果一个结构体B里嵌套另一个结构体A，还是以最大成员类型的字节对齐，但是结构体A存储起点为A内部最大成员整数倍的地方。（struct B里存有struct A，A里有char，int，double等成员，那A应该从8的整数倍开始存储。），结构体A中的成员的对齐规则仍满足自身的规则</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="keyword">struct</span> Str2 &#123;</span><br><span class="line">  <span class="keyword">double</span> a; <span class="comment">// 8字节 0 ~ 7</span></span><br><span class="line">  <span class="keyword">int</span> d; <span class="comment">// 4 字节: 8 ~ 11</span></span><br><span class="line">  <span class="keyword">short</span> b; <span class="comment">// 2字节: 12 ~ 13</span></span><br><span class="line">  <span class="keyword">char</span> c; <span class="comment">// 1字节: 14</span></span><br><span class="line">  S1 s1; <span class="comment">// 根据上面的结果，此处大小为 24 字节。此处需要注意，依据结构体嵌套对其方式，存储起始点则为最长 8 字节的倍数，即 16 ~ 39</span></span><br><span class="line">&#125; S2; <span class="comment">// 综上，40 刚好为 8 的整数倍。即如 sizeof 得出的结果为，40</span></span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/" class="post-title-link" itemprop="url">OC 对象 "+alloc" 方法内部流程</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-09-07 18:33:18" itemprop="dateCreated datePublished" datetime="2020-09-07T18:33:18+08:00">2020-09-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-09-09 21:52:35" itemprop="dateModified" datetime="2020-09-09T21:52:35+08:00">2020-09-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/OC%E5%BA%95%E5%B1%82/" itemprop="url" rel="index"><span itemprop="name">OC底层</span></a>
                </span>
            </span>

          
            <span id="/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/" class="post-meta-item leancloud_visitors" data-flag-title="OC 对象 "+alloc" 方法内部流程" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <img src="/2020/09/07/OC-%E5%AF%B9%E8%B1%A1-alloc-%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E6%B5%81%E7%A8%8B/AllocMethodflowChart.png" class="" title="This is an image">

<h2 id="示例-SomeClass-对象-alloc-方法调用"><a href="#示例-SomeClass-对象-alloc-方法调用" class="headerlink" title="示例: SomeClass 对象 alloc 方法调用"></a>示例: SomeClass 对象 alloc 方法调用</h2><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SomeClass *sc = [[SomeClass alloc] init]</span><br></pre></td></tr></table></figure>

<h4 id="重点1-对象调用-alloc，底层-C-接口-objc-alloc-init"><a href="#重点1-对象调用-alloc，底层-C-接口-objc-alloc-init" class="headerlink" title="重点1.  对象调用 alloc，底层 C 接口 objc_alloc_init"></a>重点1.  对象调用 alloc，底层 C 接口 objc_alloc_init</h4><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">+ (<span class="keyword">id</span>)alloc &#123;</span><br><span class="line">    <span class="keyword">return</span> _objc_rootAlloc(<span class="keyword">self</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// Base class implementation of +alloc. cls is not nil.</span></span><br><span class="line"><span class="comment">// Calls [cls allocWithZone:nil].</span></span><br><span class="line"><span class="keyword">id</span></span><br><span class="line">objc_alloc_init(Class cls)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> [callAlloc(cls, <span class="literal">true</span><span class="comment">/*checkNil*/</span>, <span class="literal">false</span><span class="comment">/*allocWithZone*/</span>) init];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这里要注意的是，alloc 核心方法都在 callAlloc, init 调用需要看各自类的实现，系统根类（NSObject）没有太多实现, 下面是 init 的实现。</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">id</span>)init &#123;</span><br><span class="line">    <span class="keyword">return</span> _objc_rootInit(<span class="keyword">self</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">id</span></span><br><span class="line">_objc_rootInit(<span class="keyword">id</span> obj)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">// In practice, it will be hard to rely on this function.</span></span><br><span class="line">    <span class="comment">// Many classes do not properly chain -init calls.</span></span><br><span class="line">    <span class="comment">// 根类仅仅返回对象本身</span></span><br><span class="line">    <span class="keyword">return</span> obj;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>说起 alloc/init，不得不提下他们的聚合版本 new，实际上他的内部实现等同于 alloc + init，但是为何不推荐使用呢？</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">+ (<span class="keyword">id</span>)new &#123;</span><br><span class="line">    <span class="keyword">return</span> [callAlloc(<span class="keyword">self</span>, <span class="literal">false</span><span class="comment">/*checkNil*/</span>) init];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在UIKit 或 Foundation 框架中，很多类会将 first design 方法替换成自定义 initWithXXX 方法，使用 new 将很难发现这些类初始化失败的原因，导致代码可读性降低，查错困难。</p>
<h5 id="小插曲"><a href="#小插曲" class="headerlink" title="小插曲"></a>小插曲</h5><p>Xcode 10 和 Xcode 11 在 debug 时，堆栈不太一致</p>
<p>Xcode 11 中不会在堆栈中显示调用 objc_alloc_init，只有注释中说明了这一步骤。</p>
<blockquote>
<p>对于这个问题，目前的说法是源码开源得不够充分。以下这段代码虽然未调用到，但其逻辑也是耐人寻味。 大致猜测是这个方法等于交换单次的Method Swizzling</p>
</blockquote>
<h4 id="重点2-计算要开辟的内存大小"><a href="#重点2-计算要开辟的内存大小" class="headerlink" title="重点2. 计算要开辟的内存大小"></a>重点2. 计算要开辟的内存大小</h4><p>这里需要注意，oc 对象本身需要的内存大小基础上，会进行 16 字节对其，目的是为了进行读取速度优化，空间换时间。实际上大多只需要 8 字节就能存储完成，如下为 16 字节对其代码。</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">size_t fastInstanceSize(size_t extra) <span class="keyword">const</span></span><br><span class="line">    &#123;</span><br><span class="line">        ASSERT(hasFastInstanceSize(extra));</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (__builtin_constant_p(extra) &amp;&amp; extra == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> _flags &amp; FAST_CACHE_ALLOC_MASK16;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            size_t size = _flags &amp; FAST_CACHE_ALLOC_MASK;</span><br><span class="line">            <span class="comment">// remove the FAST_CACHE_ALLOC_DELTA16 that was added</span></span><br><span class="line">            <span class="comment">// by setFastInstanceSize</span></span><br><span class="line">            <span class="keyword">return</span> align16(size + extra - FAST_CACHE_ALLOC_DELTA16);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// 16 字节对其算法</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">inline</span> size_t align16(size_t x) &#123;</span><br><span class="line">	  <span class="comment">// 抹掉末尾的0，只保留 16 的倍数</span></span><br><span class="line">    <span class="keyword">return</span> (x + size_t(<span class="number">15</span>)) &amp; ~size_t(<span class="number">15</span>); </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/" class="post-title-link" itemprop="url">使用 Xcode Preview 预览你的 UIKit ViewController</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-08-07 16:22:35 / 修改时间：17:45:33" itemprop="dateCreated datePublished" datetime="2020-08-07T16:22:35+08:00">2020-08-07</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a>
                </span>
            </span>

          
            <span id="/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/" class="post-meta-item leancloud_visitors" data-flag-title="使用 Xcode Preview 预览你的 UIKit ViewController" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>SwiftUI的拥有众多杀手级特性，其中一个就是 Xcode Preview 支持无需使用模拟器即可预览布局。让我们看看如何为你的UIKit视图控制器和视图添加支持，以便它们也可以与 Xcode Preview 一起使用。</p>
<h2 id="预备知识"><a href="#预备知识" class="headerlink" title="预备知识"></a>预备知识</h2><p>需要提前了解的一个坏消息是，Xcode Preview 对你的工程设置及电脑系统有严苛的要求。除了需要 Xcode 11+ 之外，你还需要将系统升级至 macOS Catalina，并且需要设置你的工程的最小 development target 支持版本为 iOS 13，你可以只在 Debug 环境下设置支持预览，这样就不用在发行版中添加不必要的程序。</p>
<h2 id="预览一个-View-Controller"><a href="#预览一个-View-Controller" class="headerlink" title="预览一个 View Controller"></a>预览一个 View Controller</h2><p>在让 view controllers 正确使用 Xcode Previews 之前，需要以下准备：
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/08/07/%E4%BD%BF%E7%94%A8-Xcode-Preview-%E9%A2%84%E8%A7%88%E4%BD%A0%E7%9A%84-ViewController/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/" class="post-title-link" itemprop="url">电信光猫路由改桥接配置</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-08-01 17:16:17 / 修改时间：18:26:11" itemprop="dateCreated datePublished" datetime="2020-08-01T17:16:17+08:00">2020-08-01</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%97%A0%E7%94%A8%E7%9F%A5%E8%AF%86%E5%8F%88%E8%A6%81%E5%A2%9E%E5%8A%A0%E4%BA%86/" itemprop="url" rel="index"><span itemprop="name">无用知识又要增加了</span></a>
                </span>
            </span>

          
            <span id="/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/" class="post-meta-item leancloud_visitors" data-flag-title="电信光猫路由改桥接配置" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>793</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>最近研究家庭本地组网，大家普遍吐槽光猫自带的无线网信号和稳定性一般，建议改为桥接使用自己的路由。</p>
<p>自用电信天翼光猫，默认路由模式，改桥接需要打电话预约售后上面。不想麻烦别人，自己查资料，本文也是记录下自己的爬坑过程。</p>
<h2 id="方案一：使用桥接-路由模式转换配置页（推荐）"><a href="#方案一：使用桥接-路由模式转换配置页（推荐）" class="headerlink" title="方案一：使用桥接/路由模式转换配置页（推荐）"></a>方案一：使用桥接/路由模式转换配置页（推荐）</h2>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/08/01/%E7%94%B5%E4%BF%A1%E5%85%89%E7%8C%AB%E8%B7%AF%E7%94%B1%E6%94%B9%E6%A1%A5%E6%8E%A5%E9%85%8D%E7%BD%AE/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/" class="post-title-link" itemprop="url">使用 Swift 实现双向链表</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-07-24 11:32:16 / 修改时间：12:00:18" itemprop="dateCreated datePublished" datetime="2020-07-24T11:32:16+08:00">2020-07-24</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">数据结构与算法</span></a>
                </span>
            </span>

          
            <span id="/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/" class="post-meta-item leancloud_visitors" data-flag-title="使用 Swift 实现双向链表" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>4k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>4 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <blockquote>
<p>线性表中，链表拥有更灵活的存储结构，不要求存储空间连续，对于插入和删除节点十分友好，但除了插入删除，其他大部分操作是将复杂度均为 O(n)，需要在使用时考虑具体的场景。</p>
</blockquote>
<ul>
<li><p>种类<br>链表又包括单向链表、双向链表、循环链表等形式，其优缺点各不相同。</p>
</li>
<li><p>应用场景</p>
<ul>
<li>redis 中使用的跳表则是拥有多级索引的链表升级版本，在搜索、插入、删除等操作都非常高效。</li>
<li>在工业级哈希表中，会使用链表实现桶结构，用于解决哈希冲突问题，被称为拉链法。(JDK 1.8之后采用链表+红黑树）</li>
</ul>
</li>
</ul>
<p>本文主要使用 Swift 实现双向链表，如下为代码实现。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/07/24/%E4%BD%BF%E7%94%A8-Swift-%E5%AE%9E%E7%8E%B0%E9%93%BE%E8%A1%A8/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/" class="post-title-link" itemprop="url">使用 Swift 实现顺序表</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-23 18:13:47" itemprop="dateCreated datePublished" datetime="2020-07-23T18:13:47+08:00">2020-07-23</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-24 12:50:22" itemprop="dateModified" datetime="2020-07-24T12:50:22+08:00">2020-07-24</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%B8%8E%E7%AE%97%E6%B3%95/" itemprop="url" rel="index"><span itemprop="name">数据结构与算法</span></a>
                </span>
            </span>

          
            <span id="/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/" class="post-meta-item leancloud_visitors" data-flag-title="使用 Swift 实现顺序表" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>顺序表（Sequence List），使用固定内存空间进行初始化的数据结构，可进行随机访问且时间复杂度为O(1)。</p>
<p>通常会直接使用系统标准库中的 Array 模拟，本文将使用通用化的数据结构描述顺序表。</p>
<p>如下为顺序表代码实现。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/07/23/%E7%94%A8-Swift-%E6%95%B0%E7%BB%84%E5%AE%9E%E7%8E%B0%E9%A1%BA%E5%BA%8F%E9%93%BE%E8%A1%A8/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/" class="post-title-link" itemprop="url">Mac 的无用冷知识</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-09 16:17:37" itemprop="dateCreated datePublished" datetime="2020-07-09T16:17:37+08:00">2020-07-09</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-08-01 17:10:53" itemprop="dateModified" datetime="2020-08-01T17:10:53+08:00">2020-08-01</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%97%A0%E7%94%A8%E7%9F%A5%E8%AF%86%E5%8F%88%E8%A6%81%E5%A2%9E%E5%8A%A0%E4%BA%86/" itemprop="url" rel="index"><span itemprop="name">无用知识又要增加了</span></a>
                </span>
            </span>

          
            <span id="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/" class="post-meta-item leancloud_visitors" data-flag-title="Mac 的无用冷知识" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>263</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <img src="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/fish.png" class="" title="This is an image">

<h3 id="Q：手机连接电脑后不充电，并且一直断开重连。"><a href="#Q：手机连接电脑后不充电，并且一直断开重连。" class="headerlink" title="Q：手机连接电脑后不充电，并且一直断开重连。"></a>Q：手机连接电脑后不充电，并且一直断开重连。</h3><p>A：Mac 中的 USB 进程卡死导致 USB 口无法响应，杀掉进程就好了。</p>
<p>执行以下命令就能杀死该进程。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo killall -STOP -c usbd</span><br></pre></td></tr></table></figure>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/07/09/Mac-%E7%9A%84%E8%BF%B7%E6%83%91%E8%A1%8C%E4%B8%BA%E6%94%B6%E9%9B%86/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/07/07/puppeteer-%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98-Failed-to-download-Chromium/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/07/puppeteer-%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98-Failed-to-download-Chromium/" class="post-title-link" itemprop="url">puppeteer 安装问题:Failed to download Chromium</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-07 19:40:18" itemprop="dateCreated datePublished" datetime="2020-07-07T19:40:18+08:00">2020-07-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-09 23:08:21" itemprop="dateModified" datetime="2020-07-09T23:08:21+08:00">2020-07-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%8D%9A%E5%AE%A2%E8%A3%85%E4%BF%AE%E6%8A%80%E6%9C%AF/" itemprop="url" rel="index"><span itemprop="name">博客装修技术</span></a>
                </span>
            </span>

          
            <span id="/2020/07/07/puppeteer-%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98-Failed-to-download-Chromium/" class="post-meta-item leancloud_visitors" data-flag-title="puppeteer 安装问题:Failed to download Chromium" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/07/puppeteer-%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98-Failed-to-download-Chromium/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/07/puppeteer-%E5%AE%89%E8%A3%85%E9%97%AE%E9%A2%98-Failed-to-download-Chromium/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>291</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <ul>
<li>报错问题</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ERROR: Failed to download Chromium r588429! Set &quot;PUPPETEER_SKIP_CHROMIUM_DOWNLOAD&quot; env variable to skip download.</span><br></pre></td></tr></table></figure>

<p>网上有很多解决方案，大多是修改 Chromium 下载源，或者使用 cnpm，再或者跳过下载，手动去官网下载 Chromium。</p>
<p>自测了一下都不太好用。</p>
<p>从 puppeteer 的 issue 中找到国际友人的解决方案。</p>
<ul>
<li>解决方案</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">$</span><span class="bash"> sudo npm install puppeteer@1.8.0 --unsafe-perm=<span class="literal">true</span> --allow-root</span></span><br></pre></td></tr></table></figure>

<p>亲测好用，记录一下。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/" class="post-title-link" itemprop="url">解决 gitee page 无法自动更新</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-07-07 19:30:17" itemprop="dateCreated datePublished" datetime="2020-07-07T19:30:17+08:00">2020-07-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-09 23:08:19" itemprop="dateModified" datetime="2020-07-09T23:08:19+08:00">2020-07-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%8D%9A%E5%AE%A2%E8%A3%85%E4%BF%AE%E6%8A%80%E6%9C%AF/" itemprop="url" rel="index"><span itemprop="name">博客装修技术</span></a>
                </span>
            </span>

          
            <span id="/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/" class="post-meta-item leancloud_visitors" data-flag-title="解决 gitee page 无法自动更新" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.6k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>1 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <blockquote>
<p>众所周知，国内 GitHub 的加载速度不太理想，而大多数开发者会使用 Github 的 Github Page 功能搭建博客，因此博客的访问速度也会受到影响。为了解决访问速度的问题，我们将博客转移到了 gitee 中（ OSChina 旗下 git 平台）</p>
</blockquote>
<h3 id="1-问题：使用-hexo-部署到-gitee-后，博客页面并没有更新"><a href="#1-问题：使用-hexo-部署到-gitee-后，博客页面并没有更新" class="headerlink" title="1. 问题：使用 hexo 部署到 gitee 后，博客页面并没有更新"></a>1. 问题：使用 hexo 部署到 gitee 后，博客页面并没有更新</h3><ul>
<li>原因： gitee page 只有付费版才能自动更新，免费版只能手动点击 “设置” 中的更新按钮</li>
</ul>
<h3 id="2-自动化解决方案"><a href="#2-自动化解决方案" class="headerlink" title="2. 自动化解决方案"></a>2. 自动化解决方案</h3><ul>
<li>使用 puppeteer 操作浏览器进行更新按钮点击。</li>
</ul>
<h3 id="3-源码如下"><a href="#3-源码如下" class="headerlink" title="3. 源码如下:"></a>3. 源码如下:</h3>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/07/07/gitee-page-%E6%97%A0%E6%B3%95%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yang0033.gitee.io/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
      <meta itemprop="name" content="SuperYang">
      <meta itemprop="description" content="牛肉炒饭不要香菜，老板收钱">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SuperYang`s Blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          
            <a href="/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/" class="post-title-link" itemprop="url">在 macOS 中使用 Visual Studio Code（VSCode）开发 Swift</a>
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-22 21:18:00" itemprop="dateCreated datePublished" datetime="2020-03-22T21:18:00+08:00">2020-03-22</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-09 15:59:47" itemprop="dateModified" datetime="2020-07-09T15:59:47+08:00">2020-07-09</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a>
                </span>
            </span>

          
            <span id="/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/" class="post-meta-item leancloud_visitors" data-flag-title="在 macOS 中使用 Visual Studio Code（VSCode）开发 Swift" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>1.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p><strong>Visual Studio Code</strong>（<strong>VSCode</strong>）是一款微软推出的跨平台代码编辑器，并且有数百人定期更新维护的杰出的开源项目。<strong>VSCode</strong> 是最早对 <strong>Language Server Protocol (LSP)</strong>  进行支持的开发工具，并且在不同的语言技术中也提供了杰出的开发体验。</p>
<p>同此前<a href="[https://nshipster.com/language-server-protocol/](https://nshipster.com/language-server-protocol/)">宣布</a>的目前已经发布的 <a href="https://developer.apple.com/documentation/xcode_release_notes/xcode_11_4_beta_release_notes" target="_blank" rel="noopener">Xcode</a>，现在是一个很好的时机来将这个工具集成到自己的开发工作中。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/03/22/%E5%9C%A8%20macOS%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20Visual%20Studio%20Code%EF%BC%88VSCode%EF%BC%89%E5%BC%80%E5%8F%91%20Swift/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  


  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="SuperYang"
      src="https://tva2.sinaimg.cn/crop.259.17.290.290.180/c2abdfa9jw8ez7appr3p2j20g40a2t91.jpg?KID=imgbed,tva&Expires=1594186820&ssig=BdxhDdi1Ti">
  <p class="site-author-name" itemprop="name">SuperYang</p>
  <div class="site-description" itemprop="description">牛肉炒饭不要香菜，老板收钱</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">39</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">5</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yangchao0033" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yangchao0033" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:ygrfwyc@gmail.com" title="E-Mail → mailto:ygrfwyc@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/yangchao0033" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;yangchao0033" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.jianshu.com/u/f37a8f0ba6f8" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;f37a8f0ba6f8" rel="noopener" target="_blank"><i class="fas fa-book fa-fw"></i>简书</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://t.me/superYang0033" title="Telegram → https:&#x2F;&#x2F;t.me&#x2F;superYang0033" rel="noopener" target="_blank"><i class="fab fa-telegram fa-fw"></i>Telegram</a>
      </span>
  </div>



      </div>

      
        <div id="music163player">
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=350 height=86 src="//music.163.com/outchain/player?type=2&id=31473269&auto=0&height=66">
        </iframe>
        </div>
    </div>

    

  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">SuperYang</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">157k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:23</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>













  

  

  

  <script async src="/js/cursor/fireworks.js"></script>



<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : true,
      notify     : true,
      appId      : 'zizRqalUJY55Xc5oBJKbhxpV-gzGzoHsz',
      appKey     : '64gPcVi8lIA8zVGpBSEk7uKu',
      placeholder: "留言板无需注册登录，快来评论吧。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
